#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QtMqtt/qmqttclient.h>
#include <QDateTime>
#include <QtCore/QtCore>
#include <QtNetwork/QtNetwork>
#include <QFile>
#include <QTime>


QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
    virtual void closeEvent(QCloseEvent* event) override;

    void initMqttClinet();
    void disconnectMqttClinet();

    private slots:
        void on_pBtn_Connect_clicked();

        void stateChangedSlot(QMqttClient::ClientState state);

        void errorChangedSlot(QMqttClient::ClientError error);

        void messageReceivedSlot(const QByteArray &message, const QMqttTopicName &topic = QMqttTopicName());

        void on_pBtn_Publish_clicked();

        void on_pBtn_Subscribe_clicked();

        void on_pBtn_Ping_clicked();

        void on_pBtn_ClearLog_clicked();


private:
        QMqttClient* mqttClient = nullptr;
        uint8_t connect_flag=0;
        QString init_server_ip,init_server_port,init_clientid,init_username,init_passwd;
        QString init_publish_topic,init_subscribe_topic;

        QFile configFile;
        #define CONFIG_FILE_PATH_DEFAULT "./config.ini"
        void configFileInit();


private:
    Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
